﻿using System;
using System.Diagnostics;
using System.Security;

namespace Microsoft.Coding4Fun.TweetCraft.Twitter
{
    /// <summary>
    /// A dummy Twitter implementation that writes <see cref="Trace"/> messages.
    /// </summary>
    public class TraceTwitterClient : ITwitterClient
    {
        public TraceTwitterClient()
        {
            this.Status = TwitterClientStatus.Connected;
        }

        /// <summary>
        /// Gets or sets the Twitter username.
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// Gets or sets the Twitter OAuth Token.
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// Gets or sets the Twitter password.
        /// </summary>
        public SecureString TokenSecret { get; set; }

        /// <summary>
        /// Gets a value indicating whether the Twitter client has credentials and can make an authenticated request.
        /// </summary>
        public bool HasCredentials
        {
            get
            {
                return !String.IsNullOrEmpty(UserName) &&
                       TokenSecret.Length > 0;
            }
        }

        /// <summary>
        /// Gets the status of the Twitter client.
        /// </summary>
        /// <value></value>
        public TwitterClientStatus Status
        {
            get; private set;
        }

        /// <summary>
        /// Raised when the <see cref="Status"/> changes.
        /// </summary>
        public event EventHandler StatusChanged;

        public string[] GetRequestToken()
        {
            return new string[0];
        }

        public string[] GetAccessToken(string[] requestToken, string verifier)
        {
            return new string[0];
        }

        /// <summary>
        /// Gets the tweets in the Public timeline.
        /// </summary>
        /// <returns>
        /// An array of <see cref="Tweet"/> instances.
        /// </returns>
        public Tweet[] GetPublicTimeline()
        {
            return new Tweet[0];
        }

        /// <summary>
        /// Gets the tweets in the Friends timeline.
        /// </summary>
        /// <returns>
        /// An array of <see cref="Tweet"/> instances.
        /// </returns>
        public Tweet[] GetFriendsTimeline()
        {
            return new Tweet[0];
        }

        /// <summary>
        /// Gets the replies.
        /// </summary>
        /// <returns>
        /// An array of <see cref="Tweet"/> instances.
        /// </returns>
        public Tweet[] GetMentions()
        {
            return new Tweet[0];
        }

        /// <summary>
        /// Adds a <see cref="Tweet"/> to the user's Twitter feed.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>
        /// An instance of the <see cref="Tweet"/> class.
        /// </returns>
        public Tweet AddTweet(string message)
        {
            Trace.WriteLine("AddTweet: " + message);

            return new Tweet
                   {
                       Message = message
                   };
        }

        public Tweet UploadAndPost(string picturePath)
        {
            Trace.WriteLine("UploadAndPost: " + picturePath);

            return new Tweet
            {
                Message = picturePath
            };
        }

        public Tweet UploadAndPost(string picturePath, string message)
        {
            Trace.WriteLine("UploadAndPost: " + picturePath + " " + message);

            return new Tweet
                   {
                       Message = message + " - " + picturePath
                   };
        }
    }
}
